﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
@using LeSoft.Application.Code;
<script>
    var _state = "";
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId";
    var AuditSetting = "@ViewBag.AuditSetting";
    $(function () {
        InitialPage();
        GetTree1();
        GetGrid();
    });

    function GetGrid() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["State"] = _state;
        queryJson["OrganizeId"] = _organizeid;
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_EnergyMeterReading/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            type: "post",
            datatype: "json",
            height: $(window).height() - 144.5,
            autowidth: true,
            mtype: "POST",
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "单据编号", name: "Code", index: "Code", width: 120, align: "center" },
                {
                    label: "单据时间", name: "Date", index: "Date", width: 120, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                    }
                },
                { label: "批次号", name: "BatchNo", index: "BatchNo", width: 100, align: "left" },
                { label: "抄表期间", name: "BatchDate", index: "BatchDate", width: 70, align: "center" },
                { label: "权责期间", name: "RightDate", index: "RightDate", width: 100, align: "center" },
                {
                    label: "单据状态", name: "State", index: "State", width: 70, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 1: return "待处理"; break;
                            case 2: return "派单中"; break;
                            case 3: return "进行中"; break;
                            case 4: return "已完成"; break;
                            case 5: return "已提交"; break;
                            case 6: return "通过审核"; break;
                            case 7: return "未通过审核"; break;
                            case 8: return "已驳回"; break;
                            case 9: return "已取消"; break;
                            default: return ""; break;
                        }
                    },
                    cellattr: function (rowId, val, rawObject, cm, rdata) {
                        switch (rawObject.State) {
                            case 1: return "style='background-color:#ddd'"; break;
                            case 2: return "style='background-color:#78f52d'"; break;
                            case 3: return "style='background-color:#7CCD7C'"; break;
                            case 4: return "style='background-color:#23b7e5'"; break;
                            case 5: return "style='background-color:#0f76cd'"; break;
                            case 6: return "style='background-color:#00d479'"; break;
                            case 7: return "style='background-color:#ff5722ed'"; break;
                            case 8: return "style='background-color:#ffeb3b'"; break;
                            case 9: return "style='background-color:#f32b31'"; break;
                            default: return ""; break;
                        }
                    }
                },
                {
                    label: "处理方式", name: "SendWay", index: "SendWay", width: 100, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 1: return "<span class=\"label label-info\">线下处理</span>"; break;
                            case 11: case 12: return "<span class=\"label label-info\">线上处理</span>"; break;
                            default: return "未指定处理方式"; break;
                        }
                    }
                },
                { label: "派单人", name: "SendMan", index: "SendMan", width: 100, align: "left" },
                { label: "接单人", name: "ReceiveMan", index: "ReceiveMan", width: 100, align: "left" },
                { label: "完成人", name: "CompleteMan", index: "CompleteMan", width: 100, align: "left" },
                { label: "提交人", name: "SubmitMan", index: "SubmitMan", width: 100, align: "left" },
                { label: "审核人", name: "AuditMan", index: "AuditMan", width: 100, align: "left" },
                { label: "附加说明", name: "Description", index: "Description", width: 200, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100, 500, 1000],
            pager: "#gridPager",
            sortname: 'Date desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');

            },
        });
        //查询点击事件
        $("#btn_Search").click(function () {
            SearchEvent();
            $(".ui-filter-text").trigger("click");
            $("#SelectedStartTime").html($("#StartTime").val());
            $("#SelectedEndTime").html($("#EndTime").val());
        });
        //重置事件
        $("#btn_Reset").click(function () {
            $("#Code").val("");
            //$("#SourceType").attr('data-value', '');
            //$("#BillType").attr('data-value', '');
            //$("#SourceType .ui-select-text").html('');
            //$("#BillType .ui-select-text").html('');
        });
    }
    //查询表格函数
    function SearchEvent() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["State"] = _state;
        queryJson["OrganizeId"] = _organizeid;
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../PropertyManage/CS_EnergyMeterReading/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            page: 1
        }).trigger('reloadGrid');
        GetTree1();
    }
    function GetTree1() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["OrganizeId"] = _organizeid;
        var item = {
            height: $(window).height() - 27.5,
            url: "../../PropertyManage/CS_EnergyMeterReading/GetStateTreeList?queryJson=" + JSON.stringify(queryJson),
            onnodeclick: function (item) {
                _state = item.id;
                SearchEvent();
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }
    //新增
    function btn_add() {
        //dialogOpen({
        //    id: "Form",
        //    title: "新增抄表",
        //    url: '/PropertyManage/CS_EnergyMeterReading/Form',
        //    width: "1100px",
        //    height: "800px",
        //    callBack: function (iframeId) {
        //        top.frames[iframeId].AcceptClick();
        //    }
        //});
        top.tablist.newTab({
            id: "Form",
            title: "添加抄表单",
            closed: true,
            url: top.contentPath + "/PropertyManage/CS_EnergyMeterReading/Form"
        });
    }
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        var Code = $("#gridTable").jqGridRowValue("Code");
        if (checkedRow(keyValue)) {
            top.tablist.newTab({
                id: "Form_" + Code,
                title: "编辑抄表单",
                closed: true,
                url: top.contentPath + "/PropertyManage/CS_EnergyMeterReading/Form?keyValue=" + keyValue
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PropertyManage/CS_EnergyMeterReading/RemoveForm",
                param: { keyValue: keyValue },
                success: function () {
                    SearchEvent();
                }
            })
        }
    }

    //抄表明细
    function btn_detail() {
        top.tablist.newTab({
            id: "Detail",
            title: "抄表明细",
            closed: true,
            url: top.contentPath + "/PropertyManage/CS_EnergyMeterReading/Detail"
        });
    }

    //审批流程配置
    function btn_AuditSetting() {
        if (!!AuditSetting) {
            dialogOpen({
                id: "WorkAuditSetting",
                title: '修改工单审核角色',
                url: '../../SystemManage/Setting/WorkAuditSetting?keyValue=' + AuditSetting,
                width: "700px",
                height: "550px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        } else { dialogMsg('不存在审批流程配置！', 0); }
    }

    //审核
    function btn_audit() {
        var Code = $("#gridTable").jqGridRowValue("Code");
        if (checkedRow(keyValue)) {
            top.tablist.newTab({
                id: "Form_" + Code,
                title: "编辑抄表单",
                closed: true,
                url: top.contentPath + "/PropertyManage/CS_EnergyMeterReading/Form?keyValue=" + keyValue
            });
        }
    }

    function GetIsAudit() {

    }


    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 135.5);
            }, 200);
            e.stopPropagation();
        });

        //绑定组织机构
        $("#Organize").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            description: "==请选择机构==",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    GetTree1();
                    SearchEvent();
                }
            }
        });
        $("#Organize").ComboBoxTreeSetValue(_organizeid);

        //时间
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            click: function (item) {
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                SearchEvent();
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div id="itemTree1"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td style="padding-left: 10px; width: 250px"> <div id="Organize" type="select" class="ui-select"></div></td>
                            <td>
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">单据时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" type="text" value="@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" type="text" value="@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">单据编号：</td>
                                                <td class="formValue">
                                                    <input id="Code" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            @*<tr>
                                                    <td class="formTitle">单据来源</td>
                                                    <td class="formValue">
                                                        <div id="SourceType" type="selectTree" class="ui-select">
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="formTitle">业务种类：</td>
                                                    <td class="formValue">
                                                        <div id="BillType" type="selectTree" class="ui-select">
                                                        </div>
                                                    </td>
                                                </tr>*@
                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                        <a id="lr-audit" class="btn btn-default" style="display:none;" onclick="btn_audit()" disabled><i class="fa fa-pencil-square-o"></i>&nbsp;审核</a>
                        <a id="lr-detail" class="btn btn-default" onclick="btn_detail()"><i class="fa fa-reorder"></i>&nbsp;抄表记录明细</a>
                        <a id="lr-Audit" class="btn btn-default" onclick="btn_AuditSetting()"><i class="fa fa-reorder"></i>&nbsp;抄表审批流程</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>

</div>
